package Databases;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;

public class ReadProperties {

    public static String FILE_PROPERTIES = null;
    public static PropertiesConfiguration properties = null;

    private ReadProperties() {
        try {
            properties = new PropertiesConfiguration();
            properties.setFileName(FILE_PROPERTIES);
            properties.setReloadingStrategy(new FileChangedReloadingStrategy());
            properties.setDelimiterParsingDisabled(true);
            properties.load(ReadProperties.class.getClassLoader().getResourceAsStream(FILE_PROPERTIES));

        } catch (ConfigurationException e) {
            System.err.println("Error Cargando las properties");
        }
    }

    public static String getProperty(String propiedad) {
        return properties.getString(propiedad);
    }

    public static ReadProperties getInstance(String nameProperty) {
        FILE_PROPERTIES = nameProperty;
        return ConfigurationHolder.INSTANCE;
    }

    private static class ConfigurationHolder {

        private static final ReadProperties INSTANCE = new ReadProperties();
    }
}
